package com.tyk.bookstore.front.product.util;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tyk.bookstore.front.product.model.dto.BookCardDto;
import com.tyk.bookstore.front.product.model.dto.ClazzNestDto;
import com.tyk.bookstore.front.product.model.dto.StatisticCardDto;
import com.tyk.bookstore.front.product.model.entity.BookDo;
import com.tyk.bookstore.front.product.model.entity.BookStatisticDo;
import com.tyk.bookstore.front.product.model.entity.ClassificationDo;
import com.tyk.bookstore.front.product.model.vo.BookPageVo;
import com.tyk.bookstore.front.product.model.vo.BookVo;
import com.tyk.bookstore.front.product.model.vo.ClazzNestVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

@Mapper(componentModel = "spring")
public interface MapStructProduct {
    List<ClazzNestVo> toClassificationNestList(List<ClassificationDo> classificationDoList);

    @Mapping(target = "children", ignore = true)
    ClazzNestVo toClassificationDo(ClassificationDo classificationDo);

    BookPageVo toBookPageVo(Page<BookDo> page);

    @Mappings({
            @Mapping(target = "imgList", ignore = true),
            @Mapping(target = "authorName", ignore = true),
            @Mapping(target = "publisherName", ignore = true),
            @Mapping(target = "classificationName", ignore = true),
            @Mapping(target = "classificationNameList", ignore = true),
            @Mapping(source = "book.price", target = "price")
    })
    BookVo toBookVo(BookDo book, BookStatisticDo bookStatistic);

    @Mapping(target = "children", ignore = true)
    ClazzNestVo toClassificationNestVo(ClazzNestDto dto);


    @Mappings({
            @Mapping(target = "publisherName", ignore = true),
            @Mapping(target = "collectNum", ignore = true),
            @Mapping(target = "saleNum", ignore = true),
            @Mapping(target = "payNum", ignore = true),
            @Mapping(target = "commentNum", ignore = true),
            @Mapping(target = "collected", ignore = true),
    })
    BookPageVo.Book toBookPageVo$Book(BookDo bookDo);

    @Mappings({
            @Mapping(target = "publisherName", ignore = true)
    })
    BookPageVo.Book toBookPageVo$Book(BookCardDto book, StatisticCardDto statistic);

    @Mappings({
            @Mapping(target = "children",ignore = true)
    })
    ClazzNestVo toClazzNestVo(ClazzNestDto clazzNestDto);
}
